You could write an action method for the Insert/New button instead of binding it directly to the display group insert action method. In the custom action, you would create a new Movie object, assign default values to it, and then insert the new object into the display group. However, there are two additional ways to specify default values for new enterprise objects, without making explicit assignments:
For a particular situation, one of the approaches is usually better than the other. If the default values are intrinsic to the enterprise object, assign them in the enterprise object class. For example, consider a Member class with a memberSince property. It's likely that you would automatically assign the current date to memberSince instead of forcing a user to supply a value. You'll see how to use this technique in Adding Behavior to Your Enterprise Objects.The Movies application specifies default values for newly created Movie objects using the display group, movieDisplayGroup.
public Main() { super(); NSMutableDictionary defaultValues = new NSMutableDictionary(); defaultValues.setObjectForKey("New Movie Title", "title"); movieDisplayGroup.setInsertedObjectDefaultValues(defaultValues); }
This method assigns the value "New Movie Title" as the default value for a new movie's title attribute. When movieDisplayGroup inserts a new movie (as it does when a user clicks the Insert/New button), it creates a new movie and assigns this default value to that movie.
Table of Contents
Next Section